home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / SHELLS / SZ2 / INPUT2.INC < prev    next >
Text File  |  1992-08-31  |  6KB  |  189 lines

  1.    {|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  2.  
  3.    DATA
  4.  
  5.    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
  6. CONST
  7.    MaxRecs                   = 5 ;
  8.    FldCnt                    = 4 ;
  9.    CurRec                    : longint = 1 ;
  10. TYPE
  11.    TDataRecord               = array [ 1..FldCnt ] of
  12.                                string ;
  13.    TDataArray                = array [ 1..MaxRecs ] of
  14.                                TDataRecord ;
  15. VAR
  16.    DataArray                 : TDataArray ;
  17.    {|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  18.  
  19.    DATA TRANSFER - note that we do NOT have to pay attention to the
  20.    dialog's record structure; "Get/Set DataRec" (from the GENERAL
  21.    unit) will access only sub-views which accept or return data.
  22.  
  23.    This lets us use plain, vanilla "string" type, so we can use the
  24.    dialog's TInputLine to change the acceptable length of the field.
  25.  
  26.    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
  27.    {===================================================================
  28.  
  29.    DIALOG --> BUFFER (read each TInputLine field)
  30.  
  31.    ===================================================================}
  32. procedure GetAllFields ( D : PDialog ) ;
  33. var
  34.    x                         : byte ;
  35. begin
  36.    for x := 1 to FldCnt do
  37.       GetDataRec ( D ,
  38.                    x ,
  39.                    @DataArray[CurRec][x] ) ;
  40. end ;
  41.    {===================================================================
  42.  
  43.    BUFFER --> DIALOG (writes each TInputLine field)
  44.  
  45.    ===================================================================}
  46. procedure SetAllFields ( D : PDialog ) ;
  47. var
  48.    x                         : byte ;
  49. begin
  50.    for x := 1 to FldCnt do
  51.       SetDataRec ( D ,
  52.                    x ,
  53.                    @DataArray[CurRec][x] ) ;
  54.    SetDataRec ( D , FldCnt + 1 , @CurRec ) ;
  55. end ;
  56.    {|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  57.  
  58.    FORM
  59.  
  60.    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
  61. TYPE
  62.    PForm                     = ^TForm ;
  63.    TForm                     = OBJECT ( TDialog )
  64.    EditMode                  : boolean ;
  65.    function GetHelpCtx       : word ; virtual ;
  66.    procedure HandleEvent     ( VAR Event : TEvent ) ; virtual ;
  67.                                END ;
  68.    {|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  69.  
  70.    CONTEXT - Enable hints if in "EditMode"; disable otherwise.
  71.  
  72.    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
  73. function TForm.GetHelpCtx : word ;
  74. var
  75.    W                         : word ;
  76. begin
  77.    W                         := TDialog.GetHelpCtx ;
  78.    if not EditMode then
  79.       if W >= 1000 then
  80.          W                   := hcNoContext ;
  81.    GetHelpCtx                := W
  82. end ;
  83.    {|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  84.  
  85.    EVENT
  86.  
  87.    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
  88. procedure TForm.HandleEvent ;
  89.    {-------------------------------------------------------------------
  90.    -------------------------------------------------------------------}
  91. procedure hdPrevRecord ;
  92. begin
  93.    if CurRec = 1 then
  94.    begin
  95.       buzz ;
  96.       EXIT ;
  97.    end ;
  98.    GetAllFields ( @SELF ) ;
  99.    dec ( CurRec ) ;
  100.    SetAllFields ( @SELF ) ;
  101. end ;
  102.    {-------------------------------------------------------------------
  103.    -------------------------------------------------------------------}
  104. procedure hdNextRecord ;
  105. begin
  106.    if CurRec = MaxRecs then
  107.    begin
  108.       buzz ;
  109.       EXIT ;
  110.    end ;
  111.    GetAllFields ( @SELF ) ;
  112.    inc ( CurRec ) ;
  113.    SetAllFields ( @SELF ) ;
  114. end ;
  115.    {-------------------------------------------------------------------
  116.    -------------------------------------------------------------------}
  117. procedure hdFirst ;
  118. begin
  119.    GetAllFields ( @SELF ) ;
  120.    CurRec                    := 1 ;
  121.    SetAllFields ( @SELF ) ;
  122. end ;
  123.    {-------------------------------------------------------------------
  124.    -------------------------------------------------------------------}
  125. procedure hdLast ;
  126. begin
  127.    GetAllFields ( @SELF ) ;
  128.    CurRec                    := MaxRecs ;
  129.    SetAllFields ( @SELF ) ;
  130. end ;
  131.    {-------------------------------------------------------------------
  132.    -------------------------------------------------------------------}
  133. procedure hdEdit ;
  134. begin
  135.    EditMode                  := not EditMode ;
  136.    if EditMode then
  137.    begin
  138.       SetStaticText ( @SELF , TRUE ) ;
  139.       SetBorder ( CRT.LightRed ) ;
  140.    end
  141.    else
  142.    begin
  143.       SetStaticText ( @SELF , FALSE ) ;
  144.       SetBorder ( CRT.LightGray ) ;
  145.    end ;
  146. end ;
  147.    {===================================================================
  148.  
  149.    COMMAND
  150.    
  151.    ===================================================================}
  152. procedure HandleCommand ;
  153. begin
  154.    case Event.Command of
  155.    cmFirst             : hdFirst ;
  156.    cmLast              : hdLast ;
  157.    cmNextRecord        : hdNextRecord ;
  158.    cmPrevRecord        : hdPrevRecord ;
  159.    cmEdit              : hdEdit ;
  160.    else
  161.       EXIT ;
  162.    end ;
  163.    ClearEvent ( Event ) ;
  164. end ;
  165.    {===================================================================
  166.  
  167.    KEYDOWN
  168.    
  169.    ===================================================================}
  170. procedure HandleKeyDown ;
  171. begin
  172.    if not EditMode then
  173.    begin
  174.       ClearEvent ( Event ) ;
  175.       Buzz ;
  176.       EXIT ;
  177.    end ;
  178. end ;
  179.    {- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  180.    PROCESS
  181.    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
  182. begin
  183.    case Event.What of
  184.    evCommand : HandleCommand ;
  185.    evKeyDown : HandleKeyDown ;
  186.    end ;
  187.    TDialog.HandleEvent ( Event ) ;
  188. end ;
  189.